module Tuscan
  module Iec60584
    module TypeE
      T90_RANGE = -270.0..1000.0
      EMF_RANGE = -8.825..76.373

      extend self

      def emfr_unbound t90
        if t90 < 0.0
          Polynomial.new(
             0.000000000000e+00,  0.586655087080e-01,  0.454109771240e-04, -0.779980486860e-06,
            -0.258001608430e-07, -0.594525830570e-09, -0.932140586670e-11, -0.102876055340e-12,
            -0.803701236210e-15, -0.439794973910e-17, -0.164147763550e-19, -0.396736195160e-22,
            -0.558273287210e-25, -0.346578420130e-28
          ).solve_for t90
        else
          Polynomial.new(
             0.000000000000e+00,  0.586655087100e-01,  0.450322755820e-04,  0.289084072120e-07,
            -0.330568966520e-09,  0.650244032700e-12, -0.191974955040e-15, -0.125366004970e-17,
             0.214892175690e-20, -0.143880417820e-23,  0.359608994810e-27
          ).solve_for t90
        end
      end

      def t90r_guess emf
        if emf < 0.0
          Polynomial.new(
             0.0000000e+00,  1.6977288e+01, -4.3514970e-01, -1.5859697e-01, -9.2502871e-02,
            -2.6084314e-02, -4.1360199e-03, -3.4034030e-04, -1.1564890e-05,  0.0000000e+00
          ).solve_for emf
        else
          Polynomial.new(
             0.0000000e+00,  1.7057035e+01, -2.3301759e-01,  6.5435585e-03, -7.3562749e-05,
            -1.7896001e-06,  8.4036165e-08, -1.3735879e-09,  1.0629823e-11, -3.2447087e-14
          ).solve_for emf
        end
      end
    end
  end
end

